package com.example.demo.service.impl;

import com.example.demo.entity.Teacher;
import com.example.demo.mapper.CourseMapper;
import com.example.demo.mapper.TeacherMapper;
import com.example.demo.service.CourseService;
import com.example.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;
    @Autowired
    CourseMapper courseMapper;

    @Override
    public int insertTeacher(Teacher teacher) {
        return teacherMapper.insertTeacher(teacher);
    }

    @Override
    public int deleteTeacherById(int id) {
        return teacherMapper.deleteTeacherById(id);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher);
    }

    @Override
    public Teacher selectTeacherById(int id) {
        return teacherMapper.selectTeacherById(id);
    }

    @Override
    public List<Teacher> selectAllTeachers() {

        List<Teacher> teachers = teacherMapper.selectAllTeachers();
        for(Teacher x : teachers){
            int i = courseMapper.countCoursesByTeacherId(x.getId());
            x.setCourseCount(String.valueOf(i));
        }
        return teachers;
    }

//    @Override
//    public Teacher selectTeacherWithUser(int teacherId) {
////        return teacherMapper.selectTeacherWithUser(teacherId);
//    }
}
